package com.rzjm.exercise.sys.core.dict.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rzjm.exercise.common.base.service.impl.BaseServiceImpl;
import com.rzjm.exercise.sys.core.dict.dao.DictDao;
import com.rzjm.exercise.sys.core.dict.domain.DictDO;
import com.rzjm.exercise.sys.core.dict.service.DictService;
import com.rzjm.exercise.sys.system.user.domain.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class DictServiceImpl extends BaseServiceImpl<DictDao, DictDO> implements DictService {
    @Resource
    private DictDao dictDao;

    @Override
    public List<DictDO> listType() {
        QueryWrapper qw = new QueryWrapper();
        qw.select("distinct `type` , description");
        return dictDao.selectList(qw);
    }

    @Override
    public List<DictDO> getHobbyList(UserDO userDO) {
        Map<String, Object> param = new HashMap<>(16);
        param.put("type", "hobby");
        List<DictDO> hobbyList = dictDao.selectByMap(param);
        return hobbyList;
    }

    @Override
    public List<DictDO> getSexList() {
        Map<String, Object> param = new HashMap<>(16);
        param.put("type", "sex");
        return dictDao.selectByMap(param);
    }

    @Override
    public List<DictDO> listByType(String type) {
        Map<String, Object> param = new HashMap<>(16);
        param.put("type", type);
        return dictDao.selectByMap(param);
    }

	@Override
	public List<DictDO> findByType(String type) {
		// 查询列表数据
		QueryWrapper<DictDO> qw = new QueryWrapper<>();
        qw.eq("type", type);
        qw.orderByAsc("sort");
		return dictDao.selectList(qw);
	}



    @Override
    public DictDO getMaxValueByType(String type, Integer shopId) {
        // 查询列表数据
        QueryWrapper<DictDO> qw = new QueryWrapper<>();
        qw.eq("type", type);
        qw.eq("company_id", shopId);
        qw.orderByDesc("sort");
        qw.last("limit 1");
        return dictDao.selectOne(qw);
    }
    @Override
    public DictDO getMaxValueByType(String type) {
        // 查询列表数据
        QueryWrapper<DictDO> qw = new QueryWrapper<>();
        qw.eq("type", type);
        qw.orderByDesc("sort");
        qw.last("limit 1");
        return dictDao.selectOne(qw);
    }
}
